<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>基本资料</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="__ADMIN_LAYUIMINI__/lib/layui-v2.5.5/css/layui.css" media="all">
    <link rel="stylesheet" href="__ADMIN_LAYUIMINI__/css/public.css" media="all">
    <style>
        .layui-form-item .layui-input-company {width: auto;padding-right: 10px;line-height: 38px;}
    </style>
</head>
<body>
<div class="layuimini-container">
    <div class="layuimini-main">

        <div class="layui-form layuimini-form">
            
            <div class="layui-form-item">
                <label class="layui-form-label">选择权限</label>
                <div class="layui-input-block">
                    <div id="LAY-auth-tree-index"></div>
                </div>
            </div>
            
            
            <div>{:token_field()}</div>

            <div class="layui-form-item">
                <div class="layui-input-block">
                    <input type="hidden" name="id" value="{$info.id}" />
                    <button class="layui-btn layui-btn-normal" lay-submit lay-filter="saveBtn">确认保存</button>
                </div>
            </div>
        </div>
    </div>
</div>
<script src="__ADMIN_LAYUIMINI__/lib/jquery-3.4.1/jquery-3.4.1.min.js" charset="utf-8"></script>
<script src="__ADMIN_LAYUIMINI__/lib/layui-v2.5.5/layui.js" charset="utf-8"></script>
<script src="__ADMIN_LAYUIMINI__/js/lay-config.js?v=1.0.4" charset="utf-8"></script>
<script>
    layui.use(['form','miniTab', 'authtree', 'notice'], function () {
        var form = layui.form,
            layer = layui.layer,
            notice = layui.notice,
            authtree = layui.authtree,
            miniTab = layui.miniTab;

        $.ajax({
            url: "{:url('AdminAuth/getAuthTreeList')}?id={$info.id}",
            dataType: 'json',
            success: function(res){
                console.log(res)
                var trees =  res.data;
                // 如果后台返回的不是树结构，请使用 authtree.listConvert 转换
                authtree.render('#LAY-auth-tree-index', trees, {
                    inputname: 'authids[]', 
                    layfilter: 'lay-check-auth', 
                    autowidth: true,
                    theme: 'auth-skin-default',
                    themePath: '__ADMIN_LAYUIMINI__/js/lay-module/authtree/tree_themes/'
                });
            }
        });

        //监听提交
        form.on('submit(saveBtn)', function (data) {
            data = data.field;
            url = "{:url('auth')}";
            var indexLoad = layer.load(1, {shade: [0.1,'#fff']});
            $.ajax({
                url,
                data,
                type:"POST",
                success(res){
                    layer.close(indexLoad);
                    console.log(res);
                    notice.success(res.message);
                    // var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
                    // window.parent.location.reload();
                    // parent.layer.close(index); //再执行关闭
                }
            })  
            return false;
        });

    });
</script>
</body>
</html>